package org.smartercontext.remotedeployable;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.smartercontext.contextmger.communication.Communication_Impl;
import org.smartercontext.contextmger.communication.Communication_ImplProxy;

/**
 * Servlet implementation class ServletBuyerPreferences
 */
@WebServlet("/ServletBuyerPreferences")
public class ServletBuyerPreferences extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletBuyerPreferences() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
    	try{
    	
    	HttpSession session = request.getSession();
    	
    	if(session.getAttribute("username")!=null&&session.getAttribute("userpreferences")!=null){
    		String userPrefs = (String)session.getAttribute("userpreferences");
    		
    		Communication_Impl comimpl = new Communication_ImplProxy();
    		comimpl.receiveBuyerPreferences(userPrefs, "json");
    		response.sendRedirect("menu.jsp?Success=Prefs");
    	}
    	
    	}catch (Exception e) {
			response.sendRedirect("menu.jsp?Error=1");
		}
	}
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

}
